<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <title><spring:message code="message.lable.DICqiYeZiZhiLeiXingChaKan"/></title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
							
    <section class="content-header">
        <h1><spring:message code="message.lable.DICqiYeZiZhiLeiXingChaKan"/></h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.DicManage"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.entprofileDic"/></a></li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
            <form action="${ctx}/dicEntProfile/exportExcel.html" id="exportExcel" method="post">
            <input id="fileName" name="fileName" type="hidden" value="<spring:message code="message.lable.entProfilexls"/>" />
                    <div class="input">
           			<div class="textalign"><spring:message code="message.listForm.qiYeZiZhiLeiXingMingCheng"/>：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="indiName" placeholder="<spring:message code="message.listForm.qiYeZiZhiLeiXingMingCheng"/>"  />
                    </div>
                    
                    <div class="textalign1"><spring:message code="message.lable.status"/>：</div>
                    <div class="boxinput">
                       <select id="status" name="status" class="textinput">
                           	<option value="" ><spring:message code="message.select.option"/></option>
                            <option value="1" ><spring:message code="message.button.start"/></option>
                            <option value="0" ><spring:message code="message.button.stop"/></option>
                           </select>
                     </div>
                     <div class="textalign1" >
                    <button type="button" id="selectDicEntProfile" class="btn btn-success btn-sm" onclick="search();"><spring:message code="message.button.seachSpacing"/></button>
                </div>
                </div>
                </form>
            </div>
        </div>
        
        <table class="jqgrid" id="gridlist"></table>
         <div id="gridpage"></div>
         
        <div class=" box box-warning bottongroup">
             <ms:btn url="/dicEntProfile/add.html"><label id="addNew" class="btn btn-default btn-sm"><spring:message code="message.button.addSpacing"/></label></ms:btn>
             <ms:btn url="/dicEntProfile/enable.html"><label id="batchEnable" class="btn btn-default btn-sm" onclick="batchChangeStatus(1)"><spring:message code="message.button.startSpacing"/></label></ms:btn>
             <ms:btn url="/dicEntProfile/disable.html"><label id="batchDisable" class="btn btn-default btn-sm" onclick="batchChangeStatus(0)"><spring:message code="message.button.stopSpacing"/></label></ms:btn>
      		<label onclick="exportExcel();" class="btn btn-default btn-sm"><spring:message code="message.lable.daoChu"/></label>
        </div>
  
		<div class="modal fade" id="dialog" tabindex="-1" >
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header bg-primary">
						<button type="button" class="close" data-dismiss="modal"><span >&times;</span></button>
						<h5 class="modal-title"><spring:message code="message.lable.entprofileDic"/><span id="editTitle"><spring:message code="message.button.add"/></span></h5>
					</div>
					<div class="modal-body">
						
						<div class="form-group form-group-xs">
							<label for="firstLevelIndiName" class=" control-label"><spring:message code="message.listForm.qiYeZiZhiLeiXingMingCheng"/>:</label>
							<input type="text" class="form-control" id="firstLevelIndiName" placeholder="<spring:message code="message.listForm.qiYeZiZhiLeiXingMingCheng"/>" maxlength="128" >
						</div>
						<div class="form-group form-group-xs">
							<label for="recipient-name" class=" control-label"><spring:message code="message.lable.remark"/>：</label>
							<div class="">
								<textarea rows="3" cols="" class="form-control" id="remark" placeholder="<spring:message code="message.lable.remark"/>" maxlength="1000"></textarea>
							</div>
						</div>
						
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-primary btn-sm" onclick="save();"><spring:message code="message.button.saveSpacing"/></button>
						<button type="button" class="btn btn-danger btn-sm" id="close" data-dismiss="modal"><spring:message code="message.button.closeSpacing"/></button>
					</div>
				</div>
			</div>
		</div>

    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
    
  //绑定回车
    $('#indiName,#status').bind('keydown', function(event) {
        if (event.keyCode == "13") {
            $('#selectDicEntProfile').click();
        }
    }); 
  
    $("#indiName").focus();//加载页面光标在企业资质类型名称上
    	
    	var dicEntProfileId = "";
    	
    	
    	function batchChangeStatus(status) {
    		var url = "";
    		var msg = "";
            if (status == 1){
                msg = "<spring:message code="message.button.start"/>";
                url = "${ctx}/dicEntProfile/disable.html";
            } else if (status == 0){
                msg = "<spring:message code="message.button.stop"/>";
                url = "${ctx}/dicEntProfile/enable.html";
            }
    		var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
    		if (rowIds.length <= 0) {
    			$.alert("<spring:message code="message.lable.pleaseSelect"/>"+msg+"<spring:message code="message.listForm.qiYeZiZhiLeiXing"/>", "warn");
    			return;
    		}
    		var str = "";
            var names = "";
            var count = 0;
                for (var i = 0;i < rowIds.length; i++){
                    var rowdata = $("#gridlist").jqGrid('getRowData', rowIds[i]);
                    if (status == 1){
                        if (rowdata.status == "<spring:message code="message.button.stop"/>"){
                            names += rowdata.firstLevelIndiName+",";
                            str += rowIds[i]+",";
                            count++;
                        }
                    } else {
                        if (rowdata.status == "<spring:message code="message.button.start"/>"){
                            names += rowdata.firstLevelIndiName+",";
                            str += rowIds[i]+",";
                            count++;
                        }
                    }
                }
                if (names != ""){
                    names = names.substring(0,names.length-1);
                } else {
                    $.alert("<spring:message code="message.lable.pleaseSelect"/>"+msg+"<spring:message code="message.lable.OKData"/>", "warn");
                    return;
                }
                msg += "<spring:message code="message.lable.yiXia"/><spring:message code="message.listForm.qiYeZiZhiLeiXing"/>";

    		
    		$.HN.message.confirm("<spring:message code="message.lable.OKYES"/>"+msg+"<spring:message code="message.lable.FlowerDataYESorNo"/><br/>"+names, '', '').on(function (e) {
                if (e) {
                	if (str.length > 0){
                        str = str.substring(0,str.length-1);
                    }
    		var list = [];
    		for (var i=0; i<rowIds.length; i++) {
    			rowId = rowIds[i];
    			list.push({"dicEntProfileId":rowId, "status":status});
    		}
    		$.post(url, {
    			"array" : json.jsonToString(list)
    		}, function(result) {
    			if (result.success) {
    				$.alert("<spring:message code="message.HN.alert.chengGongCaoZuo"/>"+count+"<spring:message code="message.HN.alert.tiaoShuJu"/>", "success");
                    $("#gridlist").trigger("reloadGrid");
    			} else {
    				$.alert(result.msg || "<spring:message code="message.HN.alert.fail"/>", "error");
    			}
    		}, "json");
                }
    		}); 
    	}
    	
    	function validate() {
    		var firstLevelIndiName = $.trim($("#firstLevelIndiName").val());
    		var remark = $.trim($("#remark").val());
    		if (firstLevelIndiName == null || firstLevelIndiName == "") {
    			$.alert("<spring:message code="message.yanZheng.qingShuRu"/><spring:message code="message.listForm.qiYeZiZhiLeiXingMingCheng"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
    			return false;
    		}
    		if (firstLevelIndiName != null || firstLevelIndiName != "") {
    			if(firstLevelIndiName.length>128){
    				$.alert("<spring:message code="message.listForm.qiYeZiZhiLeiXingMingCheng"/><spring:message code="message.yanZheng.changDuGuoChang"/>",  "warn");
    				return false;
    			}
    		}
    		if (remark != null || remark != "") {
    			if(remark.length>1000){
    				$.alert("<spring:message code="message.lable.remark"/>过长<spring:message code="message.yanZheng.changDuGuoChang"/>",  "warn");
    				return false;
    			}
    		}

    		return true;
    	}
    	
    	function save(){
    		if(!validate()){
    			return;
    		}
    		var firstLevelIndiName = $.trim($("#firstLevelIndiName").val());
    		var remark = $.trim($("#remark").val());
    		$.HN.message.confirm('<spring:message code="message.HN.alert.OkSaveYESorNO"/>', '', '').on(function (e) {
	               if (e) {
	            	   var url = "${ctx}/dicEntProfile/add.html";
	                   if(dicEntProfileId !=null && dicEntProfileId != ""){ 
	                	   url = "${ctx}/dicEntProfile/edit.html";  
	                   }
	               	$.ajax({
	           		   type: "POST",
	           		   url: url,
	           		   data:{
		           			firstLevelIndiName:firstLevelIndiName,
		           			dicEntProfileId:dicEntProfileId,
		           			remark:remark
	           		   },
	           		   dataType:"json",
	           		   success: function(result){
	           			   if(result.success){
	           				   $.alert("<spring:message code="message.HN.alert.success"/>", "success");
	           				   search();
	           				$('#dialog').modal('hide');
	           			   }else{
	           				$.alert(result.msg || "<spring:message code="message.HN.alert.fail"/>", "error");
	                	   }
	                   }
	                	});
	                }
        	 });
    	}
    
    	function cleanForm() {
    		$("#firstLevelIndiName").val("");
    		$("#remark").val("");
    	}
    	
    	function edit(id) {
    		dicEntProfileId = id || "";
    		cleanForm();
    		$.post("initEdit.html", {
    			dicEntProfileId : dicEntProfileId
    		},
    		function(result) {
    			if (result.success) {
    				var obj = result.rows;
    				$('.modal-title').html('<spring:message code="message.lable.DICqiYeZiZhiLeiXingBianJi"/>');
    				$("#firstLevelIndiName").val(obj.firstLevelIndiName);
    				$("#remark").val(obj.remark);
    				$('#dialog').modal({
                        keyboard: true
                    });
    			}
    			
    		}, "json");
    	}
    	
    	function search() {
    		var indiName = $("#indiName").val();
    		var status = $("#status").val();
    		
    		$("#gridlist").jqGrid('setGridParam',{  
    	        postData:{
    	        	"indiName":indiName,
    	        	"status":status
    	        },page:1
    	    }).trigger("reloadGrid"); //重新载入  
    	}
    
        $(function () {
            $('#addNew').click(function () {
            	$('.modal-title').html('<spring:message code="message.lable.DICqiYeZiZhiLeiXingXinZeng"/>');
            	dicEntProfileId = "";
				$("#firstLevelIndiName").val("");
				$("#remark").val("");
                $('#dialog').modal({
                    keyboard: true
                });
            });
            
            $("#gridlist").jqGrid({
                url: "getDicEntProfileList.html",
                mtype: "post",
                datatype: "json",
                autowidth: true,
                height: 270,
                colNames: [
					'<spring:message code="message.jqGrid.cz"/>',
                    'id',
                    '<spring:message code="message.listForm.qiYeZiZhiLeiXingBianMa"/>',
					'<spring:message code="message.listForm.qiYeZiZhiLeiXingMingCheng"/>', 
					'<spring:message code="message.lable.status"/>'
					
                ],
                colModel: [
					{ name: 'operate', width: 2, align:"center", sortable: false,
						formatter : function(val, opts, rowdata) {
							var firstLevelIndiCode = rowdata.firstLevelIndiCode;
							var firstLevelIndiName = rowdata.firstLevelIndiName;
					    	var str =  "<ms:btn url='/dicEntProfile/edit.html'><a href='javascript:edit(\""+rowdata.dicEntProfileId+"\");' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat 0px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.bianJi"/>'></a></ms:btn>";
								str += "<ms:btn url='/dicEntProfileLog/log.html'><a href='${ctx}/dicEntProfileLog/log.html?dicEntProfileId="+rowdata.dicEntProfileId+"&firstLevelIndiCode="+firstLevelIndiCode+"&firstLevelIndiName="+firstLevelIndiName+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -120px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.weiHuJiLu"/>'></a></ms:btn>";
					    	return str;
					}},
                    { name: 'dicEntProfileId', width: 10,hidden:true, align:"center", sortable: false},  
                    { name: 'firstLevelIndiCode', width: 6, align:"center", sortable: false},
                    { name: 'firstLevelIndiName', width: 8, align:"center", sortable: false},
                    { name: 'status', width: 2, align: 'center', sortable: false,
                    	cellattr:function (rowId, val, rawObject, cm) {
                            if(val == '停用'){
                                return 'style="color:red"';
                            }
                        },
                    	formatter:function(val, opts, rowdata){
                    		if(rowdata.status==1){
                    			return "<spring:message code="message.button.start"/>";
                    		}else{
                    			return "<spring:message code="message.button.stop"/>";
                    		}
                    	}	
                    }
                    
                ],
                rowNum: 20,
                rowList: [10, 20, 50,100],
                rownumbers: true,
                pager: "#gridpage",
                viewrecords: true,
                multiselect: true, 
                caption: "<spring:message code="message.list.entprofileDiclist"/>",
                jsonReader: {
                	repeatitems: false,
                    id: "dicEntProfileId"
                },
                gridComplete : function(){
                	var page = $("#gridlist").jqGrid('getGridParam','page');
            		var rows = $('#gridlist').getGridParam("rowNum");
            		var maxnum = (rows*page).toString();
            		var len = (maxnum.length)*10;
            		$('.jqgfirstrow').find('td').eq(0).css('width',len+'px');
                	$('#gridlist_rn').css('width',len+'px');
                }
            });
            
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            
            $(window).trigger("resize");
            
        });
        
        function exportExcel(){
    		$.HN.message.confirm('<spring:message code="message.lable.OKExport"/>&nbsp;<spring:message code="message.lable.entProfilexls"/>&nbsp;<spring:message code="message.lable.ma"/>', '', '').on(function (e) {
	               if (e) {
	            		  $("#exportExcel").submit();
			
	               }
         	 }); 
         	
    	} 
    </script>
</body>
</html>



